﻿using Gonte.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace MyUtilitiesTest
{
    /// <summary>
    ///This is a test class for FieldRangeValidatorTest and is intended
    ///to contain all FieldRangeValidatorTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FieldRangeValidatorTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void FieldRangeValidatorValidateNullFieldTest()
        {
            FieldRangeValidator validator = new FieldRangeValidator(10, 15);
            Assert.AreEqual(true, validator.Validate(null));
            Assert.IsNull(validator.Error);
        }

        [TestMethod()]
        public void FieldRangeValidatorValidateDateTimeTest()
        {
            DateTime minDate = new DateTime(2000, 1, 1);
            DateTime maxDate = new DateTime(2000, 1, 2);
            DateTime actualDate = new DateTime(2000, 1, 3);

            FieldRangeValidator validator = new FieldRangeValidator(minDate, maxDate);
            Assert.AreEqual(false, validator.Validate(actualDate));
            Assert.AreEqual("Value: 1/3/2000 12:00:00 AM is out of range [1/1/2000 12:00:00 AM, 1/2/2000 12:00:00 AM]", validator.Error);
        }

        [TestMethod()]
        public void FieldRangeValidatorValidateNotComparableTest()
        {
            NotComparable minNC = new NotComparable();
            NotComparable maxNC = new NotComparable();
            NotComparable actualNC = new NotComparable();

            FieldRangeValidator validator = new FieldRangeValidator(minNC, maxNC);
            Assert.AreEqual(false, validator.Validate(actualNC));
            Assert.AreEqual("Type: MyUtilitiesTest.NotComparable does not implement IComparable", validator.Error);
        }
    }
}
